package com.apes.fn.scm.settle.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.product.model.Classify;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.fn.scm.settle.model
 * @ClassName: PlatformSettleItemSummary
 * @Author: cyy
 * @CreateTime: 2023-06-09 17:16
 * @Description: 供应商对账单明细汇总
 * @Version: 1.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PlatformSettleItemSummary.CONST_TABLE_NAME)
public class PlatformSettleItemSummary extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_platform_settle_summary";
    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "供应商对账单明细汇总编码", padding = 8)
    @Comment("编码")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "platform_settle_id", referencedColumnName = "id")
    @Comment("结算单号")
    private PlatformSettle platformSettle;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    private Product product; //商品

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "classify_id", referencedColumnName = "id")
    @Comment("商品分类编码")
    private Classify classify;  //商品分类

    @Column(name = "actual_qty", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("结算数量")
    private double actualQty = 0;

    @Column(name = "amt_tax", nullable = false, columnDefinition = ApesConst.FIELD_16_4)
    @Comment("税金")
    private double amtTax = 0;

    @Column(name = "amount", nullable = false, columnDefinition = ApesConst.FIELD_16_4)
    @Comment("金额")
    private double amount = 0;

    @Column(name = "price_unit", columnDefinition = ApesConst.FIELD_16_4)
    @Comment("单价")
    private Double priceUnit = 0.0D;

    @Column(name = "actual_price_unit", columnDefinition = ApesConst.FIELD_16_4)
    @Comment("实结单价")
    private Double actualPriceUnit = 0.0D;

    @Column(name = "actual_amt_tax", columnDefinition = ApesConst.FIELD_16_4)
    @Comment("实结税金")
    private Double actualAmtTax = 0.0D;

    @Column(name = "discount_amount", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("折扣金额")
    private double discountAmount;

    @Column(name = "actual_settlement_amount", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("实结金额")
    private double actualSettlementAmount;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id")
    @Comment("税率")
    private Tax tax; //税率

}
